from flask import jsonify

SUCCESS = 200
FAIL = -1


def success_api(msg: str = "成功", data={}):
    """ 成功响应 默认值”成功“ """
    # print(f'json = {jsonify(success=True, code=SUCCESS, msg=msg, data=data)}')
    return jsonify(success=True, code=SUCCESS, msg=msg, data=data)


def fail_api(msg: str = "失败", code_id: int = FAIL, data={}):
    """ 失败响应 默认值“失败” """
    # print(jsonify(success=False, code=code_id, msg=msg))
    return jsonify(success=False, code=code_id, msg=msg, data=data)


def table_api(msg: str = "", data=None):
    """ 动态表格渲染响应 """
    res = {
        'success': True,
        'msg': msg,
        'code': SUCCESS,
        'data': data
    }
    return jsonify(res)

